package com.bong.ring.activity.config;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;

import com.bong.ring.R;
import com.bong.ring.util.Common;

public class ConfigAlertActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_config_alert);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("闹钟");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_button_ok, menu);
        return true;
    }

    boolean isEdit=false;
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
            case R.id.menu_edit:
                isEdit=true;
                break;
            case R.id.menu_confirm:
                isEdit=false;
                break;
        }
        Common.showToast(this,""+item.getItemId());
        invalidateOptionsMenu();
        return true;
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        if (isEdit) {
            menu.findItem(R.id.menu_edit).setVisible(false);
            menu.findItem(R.id.menu_confirm).setVisible(true);
        } else {
            menu.findItem(R.id.menu_edit).setVisible(true);
            menu.findItem(R.id.menu_confirm).setVisible(false);
        }
        return true;
    }
}
